import QtQuick
import QtQuick.Controls
import XYvisionCore
import GlobalData
Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Column {
            anchors.centerIn: parent
            Text {
                id: abc
                text: "aaa"//GlobalData.getMap1Value("MotorSpeed")
            }
            TextField {
                id: inputField
                placeholderText: "输入键"
            }

            TextField {
                id: valueField
                placeholderText: "输入值"
            }

            Button {
                text: "读取配置文件"
                onClicked: {
                    modbusClientThread.loadConfigSignal("C:/Users/ailin/mygitee/abc.json");

                }

            }

            Button {
                text: "连接modbus"
                onClicked: {
                    modbusClientThread.connectToDeviceSignal();
                }

            }
            Button {
                text: "读取modbus"
                onClicked: {
                    //GlobalData.setMap1Value(inputField.text, valueField.text); // 使用 GlobalData
                    //console.log("设置键: " + inputField.text + " 值: " + valueField.text);
                    modbusClientThread.readModbusValuesSignal();

                }
            }
            Button {
                text: "写入全局变量map1"
                onClicked: {
                    GlobalData.setMap1Value(inputField.text, parseInt(valueField.text,10)); // 使用 GlobalData
                    console.log("设置键: " + inputField.text + " 值: " + valueField.text);

                }
            }
            Button {
                text: "刷新变量值"
                onClicked: {
                    abc.text=GlobalData.getMap1Value("MotorSpeed");


                }
            }
            Button {
                text: "SOCKET服务器开始监听"
                onClicked: {
                    socketServer.startServer(12345);
                }
            }
            Button {
                text: "SOCKET客户端连接服务"
                Connections {
                        target: socketClient // 目标对象
                        function onConnected() { // 信号处理函数
                            console.log("Socket connected!");
                            // 在这里添加你的逻辑
                        }
                    }
                Connections {
                        target: socketServer // 目标对象
                        function onNewConnection() { // 信号处理函数
                            console.log("Socket有新的连接!");
                            // 在这里添加你的逻辑
                        }
                    }
                onClicked: {
                   socketClient.connectToServer("127.0.0.1", 12345);

                }
            }

        }

}
